// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_HR_CAR_RENTING
// * CreateDate    : 2011/11/7 12:58:39
// * Creater       : CodeSmith
// * LastChangeDate: 2011/11/7 12:58:39
// * LastChanger   : 2011/11/7 12:58:39
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;

namespace ESOL.Business.Hr
{
/// <summary>
    /// HrCarRenting
    /// </summary>
    public partial class HrCarRentingBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objHrCarRentingEntity">Entity</param>
        /// <returns>Entity</returns>
        public static HrCarRentingEntity GetHrCarRenting(HrCarRentingEntity objHrCarRentingEntity)
        {
            return DataAccess.SelectSingle<HrCarRentingEntity>(objHrCarRentingEntity);
        }
        public static DataTable GetByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"CR.*, P.NAME_CN AS PERSON_NAME, D.DEPARTMENT_NAME, 
								CASE WHEN CR.END_MILEAGE - CR.START_MILEAGE < 0 THEN 0 ELSE CR.END_MILEAGE - CR.START_MILEAGE END AS TOTAL_MILEAGE
                                FROM HR_CAR_RENTING CR
                                LEFT JOIN MST_PERSON P ON P.PERSON_ID = CR.PERSON_ID
                                LEFT JOIN MST_DEPARTMENT D ON D.DEPARTMENT_ID = CR.DEPARTMENT_ID
                                WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        public static HrCarRentingEntity GetById(string rentingId)
        {
            if (string.IsNullOrEmpty(rentingId))
            {
                return null;
            }
            HrCarRentingEntity entity = new HrCarRentingEntity();
            entity.RentingId = rentingId;
            return DataAccess.SelectSingle<HrCarRentingEntity>(entity);
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objHrCarRentingEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertHrCarRenting(HrCarRentingEntity objHrCarRentingEntity)
        {
            return DataAccess.Insert(objHrCarRentingEntity);
        }

        public static bool InsertHrCarRenting(List<HrCarRentingEntity> objHrCarRentingEntityList)
        {
            return DataAccess.Insert(objHrCarRentingEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objHrCarRentingEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateHrCarRenting(HrCarRentingEntity objHrCarRentingEntity)
        {
            return DataAccess.Update(objHrCarRentingEntity);
        }

        public static bool UpdateHrCarRenting(List<HrCarRentingEntity> objHrCarRentingEntityList)
        {
            return DataAccess.Update<HrCarRentingEntity>(objHrCarRentingEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objHrCarRentingEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteHrCarRenting(HrCarRentingEntity objHrCarRentingEntity)
        {
            return DataAccess.Delete(objHrCarRentingEntity);
        }

        public static bool DeleteHrCarRenting(List<HrCarRentingEntity> objHrCarRentingEntityList)
        {
            return DataAccess.Delete<HrCarRentingEntity>(objHrCarRentingEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetHrCarRentingAll()
        {
            return DataAccess.SelectAllDataSet<HrCarRentingEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<HrCarRentingEntity> GetHrCarRentingAllList()
        {
            return DataAccess.SelectAll<HrCarRentingEntity>();
        }
        #endregion
	}
	
	
}	

